const express = require('express')
const app = express()
const packInfo = require("./packInfo.js") 
const bodyParser = require("body-parser")
var dbserver = require('./dbserver.js')

//使用bodyParser插件
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

//设置允许跨域访问该服务.
app.all('*', function(req, res, next) {
	res.header('Access-Control-Allow-Origin', '*');
	//Access-Control-Allow-Headers ,可根据浏览器的F12查看,把对应的粘贴在这里就行
	res.header('Access-Control-Allow-Headers', 'Content-Type');
	res.header('Access-Control-Allow-Methods', '*');
	res.header('Content-Type', 'application/json;charset=utf-8');
	next();
});  

// 调用路由文件
require('./router.js')(app);

app.listen(packInfo.port, () => console.log(`服务器启动成功，端口号为： ${packInfo.port}!`))
